import nyNetwork from "@/api/nyBaseNetwork";
import DZModelPage from "@/model/DZModelPage";
import uploadFile from "@/utils/DZUploadFile";
import nyMessageToast from "@/utils/NYMessageToast";
import DZModelAssess from "../model/DZModelAssess";

class DZServiceAssess {

    str_assess_name = "";

    list_assess: Array<DZModelAssess> = [];

    m_page = new DZModelPage(7);

    m_assess: DZModelAssess = new DZModelAssess();



    net_list_assess() {
        var list_data = [];
        var params = { ...this.m_page, name: this.str_assess_name }
        nyNetwork.net("测评列表", params, data => {
            this.m_page.total = data.total;
            var dataList = data.list;
            for (const item of dataList) {
                var assess = new DZModelAssess();
                assess.id = item.iId ?? '';
                assess.name = item.sName ?? '';
                assess.english = item.sEnglishName ?? '-';
                assess.logoId = item.sLogo;
                assess.logo = nyNetwork.image(assess.logoId);
                assess.listLogoId = item.sListLogo;
                assess.listLogo = nyNetwork.image(assess.listLogoId);
                assess.logoList.push(assess.logo)
                assess.option = item.iOptionType ?? 1;
                assess.introduce = item.sIntroduce ?? '';
                assess.guide = item.sGuide ?? '';
                assess.questionNum = item.iQuestionNum ?? 0;
                assess.ruleId = item.iRuleId;
                assess.reportDes = item.sReportDes ?? '';
                assess.erCodeUrl = item.erCodeUrl ?? '';
                list_data.push(assess);
            }
            this.list_assess = list_data;
        })
    }


    net_list_assess_dic() {
        var list_data = [];
        nyNetwork.net("测评字典列表", {}, data => {
            for (const item of data) {
                var assess = new DZModelAssess();
                assess.id = item.iId ?? '';
                assess.name = item.sName ?? '';
                list_data.push(assess);
            }
            this.list_assess = list_data;
        })
    }

    net_upload_image(file) {
        uploadFile.uploadImage(file,
            (res) => {
            }, (res) => {
                nyMessageToast.success("图片上传成功")
                this.m_assess.logoId = res;
            }, (res) => {
                nyMessageToast.error("图片上传失败")
            });
    }

    net_upload_list_image(file) {
        uploadFile.uploadImage(file,
            (res) => {
            }, (res) => {
                nyMessageToast.success("图片上传成功")
                this.m_assess.listLogoId = res;
            }, (res) => {
                nyMessageToast.error("图片上传失败")
            });
    }

    net_add_assess(success: () => void) {
        var params = {
            name: this.m_assess.name,
            english: this.m_assess.english,
            logo: this.m_assess.logoId,
            listLogo: this.m_assess.listLogoId,
            option: this.m_assess.option,
            introduce: this.m_assess.introduce,
            guide: this.m_assess.guide,
            reportDes: this.m_assess.reportDes
        }
        console.log("net_add_assess", params)
        nyNetwork.net("添加测评", params, () => {
            success();
        })

    }

    net_edit_assess(success: () => void) {
        var params = {
            id: this.m_assess.id,
            name: this.m_assess.name,
            english: this.m_assess.english,
            logo: this.m_assess.logoId,
            listLogo: this.m_assess.listLogoId,
            option: this.m_assess.option,
            introduce: this.m_assess.introduce,
            guide: this.m_assess.guide,
            reportDes: this.m_assess.reportDes
        }
        console.log("net_add_assess", params)
        nyNetwork.net("编辑测评", params, () => {
            success();
        })

    }



}
export default DZServiceAssess;